package com.flyqiu.flow.bpmn.base;

import com.alibaba.fastjson2.JSONArray;
import com.alibaba.fastjson2.JSONObject;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import com.flyqiu.common.tools.StringTools;

import java.util.HashSet;
import java.util.Set;

@Data
@Schema(name = "候选人配置")
public class ElementCandidateConfig {
    @Schema(name = "类别")
    private String categoryKey;
    @Schema(name = "标识")
    private String candidateKey;
    @Schema(name = "配置值")
    private Set<String> configVal;

    public ElementCandidateConfig(JSONObject jsonObject) {
        categoryKey = jsonObject.getString("categoryKey");
        candidateKey = jsonObject.getString("candidateKey");
        JSONArray array = jsonObject.getJSONArray("configVal");
        if (array == null || array.isEmpty()) {
            return;
        }
        int size = array.size();
        int index = 0;
        configVal = new HashSet<>();
        String temp;
        while (index < size) {
            temp = array.getString(index);
            index = index + 1;
            if (StringTools.isAllBlank(temp) || configVal.contains(temp)) {
                continue;
            }
            configVal.add(array.getString(index));
        }
    }
}
